/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.Produccion;

import Atxy2k.CustomTextField.RestrictedTextField;
import Controlador.Bean.Produccion.ProductoxFase;
import javax.swing.JOptionPane;
import lib.Validaciones;

/**
 *
 * @author Nadhia
 */
public class modificarIngrediente extends javax.swing.JInternalFrame {

    /**
     * Creates new form modificarIngrediente
     */
    ProductoxFase  proxfa;
    buscarIngrediente bi;
    public modificarIngrediente(ProductoxFase proxfa, buscarIngrediente bi) {
        initComponents();
        this.proxfa = proxfa;
        this.bi = bi;
        RestrictedTextField restricted = new RestrictedTextField(txtCantidad);
         restricted.setLimit(5);
//         restricted.setOnlyNums(true);
    }
    
    public int validar(){
        int error = 0;
        boolean vali1 = Validaciones.validarReal(txtCantidad.getText());
        if(txtCantidad.getText().isEmpty()) {
            error=2;
        }
        else
           if(!vali1){
            error=1;}
//           else 
//            if (txtHorasM.getText().isEmpty()){
//                error=4;
//            }
//            else
//            if(!vali2){
//            error=3;}    
                
            
        
//        int indice = (int)cmbTipo.getSelectedIndex();
//        System.out.println("indice...."+indice);
//        System.out.println("fecha...."+jdpFecha.getDate());
//        if(txtNombre.getText().isEmpty()){
//        error=1;}
//        else if((jdpFecha.getDate()== null) || (jdpFecha.getDate().after(today))){
//        error=2; }
//        else if((indice==0))
//        { error=3;  }
//        else if(txtDescripcion.getText().isEmpty()){
////        error=4;    
//        }
        
        
        
        return error;
        
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        txtCantidad = new javax.swing.JTextField();
        btnAceptar = new javax.swing.JButton();

        setClosable(true);
        setTitle("Modificar Cantidad de Ingrediente");

        jLabel1.setText("Nueva Cantidad:");

        txtCantidad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCantidadActionPerformed(evt);
            }
        });

        btnAceptar.setText("Aceptar");
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(txtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(78, 78, 78)
                        .addComponent(btnAceptar)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnAceptar)
                .addContainerGap(40, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
        // TODO add your handling code here:
        try {
            int error = validar();  
           
           if(error==1){
           JOptionPane.showMessageDialog(this,"Cantidad debe ser número entero", "Advertencia", JOptionPane.OK_OPTION);
               
           }
           else 
           if(error==2){
               JOptionPane.showMessageDialog(this,"Ingrese Cantidad", "Error en ingreso de Datos", JOptionPane.OK_OPTION);
           }
//            else
//               if(txtCantidad.getText().isEmpty()){
//           JOptionPane.showMessageDialog(this,"Selecciona un ingrediente", "Advertencia", JOptionPane.OK_OPTION);
//               
//           }
//           else 
//           if(error==4){
//               JOptionPane.showMessageDialog(this,"Ingrese Preparación Masa", "Error en ingreso de Datos", JOptionPane.OK_OPTION);
//           }
//               if(vseleccionfases.isEmpty()){
//               JOptionPane.showMessageDialog(this,"Selecciona mínimo un proceso", "Error en ingreso de Datos", JOptionPane.OK_OPTION);
//           } 
//           else
//            if(error==4){
//               JOptionPane.showMessageDialog(this,"Ingrese una descripcion");
//           }  
           else
            if(error==0){
                int confirmado = JOptionPane.showConfirmDialog(this,"¿Desea modificar la cantidad del producto?");
                if (confirmado == JOptionPane.OK_OPTION){
                    proxfa.setCantidad(Double.parseDouble(txtCantidad.getText()));
                    Controlador.Service.Produccion.GestionProduccion.actualizarProductoxFase(proxfa);
                    System.out.println("actualiza la cantidad");   
                    dispose();
                    bi.actualiza();
                }
//                
                
            }
            
        }
        catch(Exception ex) { 
            System.out.println("nno guarda");
            
            
            
        }
        
    }//GEN-LAST:event_btnAceptarActionPerformed

    private void txtCantidadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCantidadActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCantidadActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField txtCantidad;
    // End of variables declaration//GEN-END:variables
}
